/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jwu2.addondb;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import jwu2.core.Addon;
import jwu2.core.Site;
import lombok.Data;
import lombok.Getter;

/**
 *
 * @author Rolf
 */
public class AddonDBEntry implements Serializable {
    @Getter private String addonName;
    private Map<Site, Addon> addons;
    private long lastUpdated;
    
    public AddonDBEntry(String name) {
        lastUpdated = System.currentTimeMillis();
        addons = new HashMap<Site, Addon>();
        addonName = name;
    }
    
    public Addon getAddonFromSite(Site site) {
        return addons.get(site);
    }
    
    public void addAddonAvaliableFromSite(Addon a, Site s) {
        addons.put(s, a);
    }
    
    public void markAsUpdated() {
        lastUpdated = System.currentTimeMillis();
    }
    
    public long getLastUpdated() {
        return lastUpdated;
    }
    
    public boolean containsAddon(Addon a) {
        return addons.values().contains(a);
    }
    
    public boolean containsAddonFromSite(Addon a, Site s) {
        return addons.get(s) != null;
    }
    
    public Set<Site> getSitesAvaliableFrom() {
        return addons.keySet();
    }
    
    public boolean hasAddonFromSite(Site s) {
        return addons.keySet().contains(s);
    }
    
    public void removeAddonFromSite(Site s) {
        addons.remove(s);
    }
}
